package com.hospital.controller;

import com.hospital.service.RegisterService;
import com.hospital.vo.RegisterVO;
import com.hospital.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;


/**
 * @author coder_zzm
 * @date 2022/3/29 10:58
 */
@Slf4j
@RestController
@RequestMapping("/register")
public class RegisterController {

    @DubboReference(check = false)
    private RegisterService registerService;

    /**
     * 查询所有挂号信息
     *
     * @param pageNum  页码
     * @param pageSize 数量
     * @return 返回所有的结果集
     */
    @GetMapping("/getAll")
    public ResponseVO getAll(@RequestParam(defaultValue = "1") int pageNum,
                             @RequestParam(defaultValue = "5") int pageSize) {
        return registerService.getAll(pageNum, pageSize);
    }

    /**
     * 根据条件查询挂号信息
     *
     * @param rid          编号
     * @param registerName 姓名
     * @param department   科室
     * @return 挂号的详细信息
     */
    @GetMapping("/findRegister")
    public ResponseVO findRegister(String rid, String registerName, String department) {
        log.debug("rid = " + rid);
        log.debug("registerName = " + registerName);
        log.debug("department = " + department);
        return registerService.findRegister(rid, registerName, department);
    }

    /**
     * 添加信息
     *
     * @param registerVO 统一 vo
     * @return 单条记录
     */
    @PostMapping("/addRegister")
    public ResponseVO addRegister(RegisterVO registerVO) {
        log.debug("registerVO = " + registerVO);
        return registerService.addRegister(registerVO);
    }

    /**
     * 批量删除
     *
     * @param rids 编号
     * @return 是否删除成功和受影响行数
     */
    @DeleteMapping("/batchDelete")
    public ResponseVO batchDelete(String[] rids) {
        return registerService.batchDelete(rids);
    }

    /**
     * 根据编号查询单条信息
     *
     * @param rid 编号
     * @return 单条记录
     */
    @GetMapping("/getRegisterById")
    public ResponseVO getRegisterById(String rid) {
        log.debug("rid = " + rid);
        return registerService.getRegisterById(rid);
    }

    /**
     * 修改信息
     *
     * @param registerVO 统一 vo
     * @return 单条记录
     */
    @PutMapping("/updateRegister")
    public ResponseVO updateRegister(RegisterVO registerVO) {
        return registerService.updateRegister(registerVO);
    }
}
